package com.example.NeteaseCloudMusicApi.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.NeteaseCloudMusicApi.R;
import com.example.NeteaseCloudMusicApi.entity.Result;
import com.example.NeteaseCloudMusicApi.ui.activity.ListSongActivity;

import java.util.List;

public class RecommendSongListAdapter extends RecyclerView.Adapter<RecommendSongListAdapter.ViewHolder> {

    private List<Result> mResult;
    private Context context;

    public RecommendSongListAdapter(Context context, List<Result> mResult) {
        this.mResult = mResult;
        this.context = context;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView image;
        TextView name;
        public ViewHolder (View view) {
            super(view);
            image = view.findViewById(R.id.showImage_start);
            name = view.findViewById(R.id.song_list_introduction);
        }
    }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_pager_content,parent,false);
            ViewHolder holder = new ViewHolder(view);
            return holder;
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position){
            //加载图片和文字
            Glide.with(context).load(mResult.get(position).getPicUrl()).into(holder.image);
            holder.name.setText(mResult.get(position).getName());

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, ListSongActivity.class);
                    context.startActivity(intent);
                }
            });
        }

        @Override
        public int getItemCount(){
            return mResult.size();
        }
}
